﻿using MySql.Data.MySqlClient;
using System;
using System.Data;

namespace Moqikaka.DAL
{
    /// <summary>
    /// 
    /// </summary>
    public class PlayerReturn : GameBaseDAL
    {

        #region  属性

//        static string _getLastJoinPlayerTime = @"SELECT userid,PartnerId,PlayerId,LinkLastLoginTime FROM joinplayerreturn 
//WHERE userid=@UserId AND PartnerId=@PartnerId 
//ORDER BY JoinTime DESC LIMIT 0,1;";

//        static string _insertUpdataCommand = @"replace into joinplayerreturn (userid,PartnerId,playerid,LinkLastLoginTime) values
//            (@UserId,@partnerId,@playerid,@LinkLastLoginTime)";



        static string _updataPlayerReturn = @"replace into joinplayerreturn (userid,PartnerId,LinkLastLoginTime,isuse) values
            (@UserId,@partnerId,@LinkLastLoginTime,@isuse)";

        static string _queryPlayerReturn = @"select userid,PartnerId,LinkLastLoginTime,isuse from  joinplayerreturn where
 userid=@UserId AND PartnerId=@PartnerId ";

        #endregion

        #region 函数


        /// <summary>
        /// 设置玩家回归活动表
        /// </summary>
        /// <param name="userId">userId</param>
        /// <param name="partnerId">partnerId</param>
        /// <param name="playerid">playerid</param>
        /// <param name="linkLastLoginTime">关联的最后一次登录时间</param>
        /// <param name="isUse">是否使用</param>
        /// <returns>是否成功</returns>
        public static bool SetPlayerReturn(string userId, Int32 partnerId ,DateTime linkLastLoginTime, bool isUse)
        {

            MySqlParameter[] paramList = new MySqlParameter[]
			{
				new MySqlParameter("@UserId", userId),
				new MySqlParameter("@PartnerId", partnerId),
				new MySqlParameter("@linkLastLoginTime", linkLastLoginTime),
				new MySqlParameter("@isUse", isUse)
			};

            return ExecuteNonQuery(GameBaseDAL.DBConnectionString, _updataPlayerReturn, paramList) > 0;
        }

        /// <summary>
        /// 获取玩家回归活动
        /// </summary>
        /// <param name="userId">userId</param>
        /// <param name="partnerId">partnerId</param>
        /// <returns></returns>
        public static DataTable GetPlayerReturn(string userId, Int32 partnerId)
        {

            MySqlParameter[] paramList = new MySqlParameter[]
			{
				new MySqlParameter("@UserId", userId),
				new MySqlParameter("@PartnerId", partnerId),
			};

            return ExecuteDataTable(GameBaseDAL.DBConnectionString, _queryPlayerReturn, paramList);
        }



        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="userId"></param>
        ///// <param name="partnerId"></param>
        ///// <returns></returns>
        //public static DataTable GetLastJoinTime(string userId, Int32 partnerId)
        //{
        //    MySqlParameter[] paramList = new MySqlParameter[]
        //    {
        //        new MySqlParameter("@UserId", userId),
        //        new MySqlParameter("@PartnerId", partnerId)
        //    };

        //    return ExecuteDataTable(GameBaseDAL.DBConnectionString, _getLastJoinPlayerTime, paramList);
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="userId"></param>
        ///// <param name="partnerId"></param>
        ///// <param name="playerId"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public static bool InsertJoinRecord(string userId, Int32 partnerId,string playerId,DateTime time)
        //{
        //    MySqlParameter[] paramList = new MySqlParameter[]
        //    {
        //        new MySqlParameter("@UserId", userId),
        //        new MySqlParameter("@partnerId", partnerId),
        //        new MySqlParameter("@playerId", playerId),
        //        new MySqlParameter("@jointime", time)
        //    };
        //    return ExecuteNonQuery(GameBaseDAL.DBConnectionString, _insertCommand, paramList) > 0;
        //}

        #endregion
    }
}
